﻿#region Class Information
/*----------------------------------------------------------------------------------
// File:           SimpleCarScript.cs
// Project:          $projectName$
// Solution:           $solutionName$
// Description:        $description$
//
// Change History:
// Name                            
// Date                                          
// Version  
// Description                    
// ----------------------------------------------------------------------------------
// $programmer$  $date$             1.0     Created
// ----------------------------------------------------------------------------------*/
#endregion

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SimpleCarScript : MonoBehaviour
{
	#region Variables
	// Exposed
	public Transform Wheel_FR;
	public Transform Wheel_FL;
	public Transform Wheel_BR;
	public Transform Wheel_BL;
	#endregion

	#region Methods
	// Use to initialize variable and references
	private void Awake()
	{

	}
	// Use to send informationen between scripts
	private void Start()
	{

	}
	// Is called once per frame
	private void Update()
	{
		float hor = Input.GetAxis( "Horizontal" );
		float ver = Input.GetAxis( "Vertical" );

		RaycastHit _fr, _fl, _br, _bl;
		Vector3 _down = -transform.up;

		Physics.Raycast( Wheel_FR.position, _down, out _fr, Mathf.Infinity, ~( 1 << LayerMask.NameToLayer( "Car" ) ) );
		Physics.Raycast( Wheel_FL.position, _down, out _fl, Mathf.Infinity, ~( 1 << LayerMask.NameToLayer( "Car" ) ) );
		Physics.Raycast( Wheel_BR.position, _down, out _br, Mathf.Infinity, ~( 1 << LayerMask.NameToLayer( "Car" ) ) );
		Physics.Raycast( Wheel_BL.position, _down, out _bl, Mathf.Infinity, ~( 1 << LayerMask.NameToLayer( "Car" ) ) );

		Debug.Log( _fr.point );

		Vector3 _frontLeftUp = Vector3.Cross( _bl.point - _fl.point, _fr.point - _fl.point );
		Vector3 _frontRightUp = Vector3.Cross( _fl.point - _fr.point, _br.point - _fr.point );
		Vector3 _backLeftUp = Vector3.Cross( _br.point - _bl.point, _fl.point - _bl.point );
		Vector3 _backRightUp = Vector3.Cross( _fr.point - _br.point, _bl.point - _br.point );



		Debug.DrawRay( Wheel_FL.position, _frontLeftUp );
		Debug.DrawRay( Wheel_FR.position, _frontRightUp );
		Debug.DrawRay( Wheel_BL.position, _backLeftUp );
		Debug.DrawRay( Wheel_BR.position, _backRightUp );


		// test
		Debug.Log( "afjasdf" );
		Vector3 upDir =	( _frontLeftUp + _frontRightUp + _backLeftUp + _backRightUp ).normalized;
	}
	#endregion
}
